package com.quick.develop.flowable.mapper;

import com.quick.develop.flowable.domain.rule.BpmProcessRule;
import com.quick.develop.flowable.utils.mybatis.mapper.BaseMapperX;
import com.quick.develop.flowable.utils.mybatis.query.QueryWrapperX;

import java.util.List;

/**
 * @author junyuan.liu
 * @description:
 * @date 2022/5/18 15:09
 */
public interface BpmProcessRuleMapper extends BaseMapperX<BpmProcessRule> {

    default List<BpmProcessRule> selectListByProcessDefinitionId(String processDefinitionId){
        return selectList(new QueryWrapperX<BpmProcessRule>()
                .eq("PROCESS_DEFINITION_ID", processDefinitionId));
    }

    default List<BpmProcessRule> selectListByModeId(String modelId){
        return selectList(BpmProcessRule::getModelId, modelId);
    }
    
    default List<BpmProcessRule> selectListByModeKey(String modelKey) {
        return selectList(BpmProcessRule::getModelKey, modelKey);
    }
    
    default List<BpmProcessRule> selectListByModelIdAndNodeCode(String modelId, String nodeCode){
        return selectList(new QueryWrapperX<BpmProcessRule>()
                .eq("MODEL_ID", modelId)
                .eq("NODE_CODE", nodeCode));
    }

    default List<BpmProcessRule> selectListByModelKeyAndNodeCode(String modelKey, String nodeCode){
        return selectList(new QueryWrapperX<BpmProcessRule>()
                .eq("MODEL_KEY",modelKey)
                .eq("NODE_CODE",nodeCode));
    }

    /**
     * 查询预指定的数据
     * @param modelKey
     * @return
     */
    default List<BpmProcessRule> selectListByModelKey(String modelKey){
        return selectList(new QueryWrapperX<BpmProcessRule>()
                .eq("MODEL_KEY",modelKey)
                .eq("ASSIGNEE_TYPE",'3')
                .orderByAsc("NODE_CODE"));
    }


    /**
     * 查询流程规则
     */
    default List<BpmProcessRule> selectAllListByModelKey(String modelKey){
        return selectList(new QueryWrapperX<BpmProcessRule>()
                .eq("MODEL_KEY",modelKey)
                .orderByAsc("NODE_CODE"));
    }
}
